﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using Light.Framework.Model;
using System.ComponentModel;
using Light.Utility;

namespace Light.Weixin.Model
{
    /// <summary>
    /// 微信用户
    /// </summary>
    [Traceable]
    [ImportField]
    [ActiveRecord]
    [DisplayName("微信用户")]
    public class WxUserInfo : Entity
    {
        /// <summary>
        /// 昵称
        /// </summary>
        [Property]
        [Searchable("昵称")]
        public string Nickname { get; set; }
        /// <summary>
        /// 对于当前公众号的openid
        /// </summary>
        [Property]
        [Searchable("openid")]
        public string OpenID { get; set; }
        /// <summary>
        /// unionid
        /// </summary>
        [Property]
        [Searchable("unionid")]
        public string UnionID { get; set; }

        /// <summary>
        /// 微信头像
        /// </summary>
        [Property]
        public string HeadImgUrl { get; set; }

        /// <summary>
        /// 国家
        /// </summary>
        [Property]
        public string Country { get; set; }

        /// <summary>
        /// 省份
        /// </summary>
        [Property]
        public string Province { get; set; }

        /// <summary>
        /// 城市
        /// </summary>
        [Property]
        public string City { get; set; }

        /// <summary>
        /// 是否为男性
        /// </summary>
        [Property]
        public bool IsMale { get; set; }

        /// <summary>
        /// 是否关注
        /// </summary>
        [Property]
        public bool IsSubscribe { get; set; }

        /// <summary>
        /// 邀请人
        /// </summary>
        [BelongsTo("WxUserInfo_ID")]
        public WxUserInfo Inviter { get; set; }

        /// <summary>
        /// 所属微信公众号
        /// </summary>
        [BelongsTo("WxApp_ID")]
        public WxApp WxApp { get; set; }

        /// <summary>
        /// 关联用户
        /// </summary>
        [BelongsTo("User_ID", NotFoundBehaviour = NotFoundBehaviour.Ignore, Cascade = CascadeEnum.None)]
        public User User { get; set; }

        public override string ToString()
        {
            return string.Format("{0}  OpenID：{1} 来自：{2}"
                , Nickname, OpenID, WxApp != null ? WxApp.Name : "");
        }
    }
}
